using System;
using System.ComponentModel;
using System.Linq.Expressions;
using TFS.Kanban.Commons.Extensions;

namespace TFS.Kanban.Commons
{
    public class ViewModelBase<T> : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;

        /// <summary>
        /// Helper to raise PropertyChanged events using strongly-typed
        /// Lambda syntax like: OnPropertyChanged(x => x.SomeProperty);
        /// </summary>
        /// <param name="property">a Lambda specifying the property that is changing.</param>
        protected void OnPropertyChanged(Expression<Func<T, object>> property)
        {
            var name = property.GetPropertyName();

            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(name));
            }
        }
    }
}
